package com.project.controller;

import com.framework.core.result.APIObjResponse;
import com.framework.core.result.BasePage;
import com.project.base.BaseController;
import com.project.biz.CmsProductRecommendBiz;
import com.project.common.model.UserInfo;
import com.project.pojo.dto.ProductDTO;
import com.project.pojo.model.AddRecommendProductModel;
import com.project.pojo.model.DelRecommendProductModel;
import com.project.pojo.model.GetRecommendProductModel;
import com.project.pojo.model.UpdateRecommendProductSortModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 推荐商品
 * @Author: zhuchi
 * @CreateDate: 2020/11/20 1:11
 * @Version: 1.0
 */
@Api(value = "CmsProductRecommendController", description = "推荐商品")
@RestController
@RequestMapping("/recommendProduct")
@Slf4j
public class CmsProductRecommendController extends BaseController {

    /**
     * 商品推荐业务层接口类
     */
    @Autowired
    private CmsProductRecommendBiz productRecommendBiz;

    /**
     * 分页查询推荐商品（前后台通用）
     * @return
     */
    @ApiOperation(value = "分页查询推荐商品（前后台通用）", httpMethod = "POST")
    @PostMapping(value = "/selectRecommendProduct")
    public APIObjResponse<BasePage<ProductDTO>> selectRecommendProduct(@RequestBody GetRecommendProductModel recommendProductModel){
        BasePage<ProductDTO> basePage = this.productRecommendBiz.selectRecommendProduct(recommendProductModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 添加推荐商品
     * @return
     */
    @ApiOperation(value = "添加推荐商品", httpMethod = "POST")
    @PostMapping(value = "/addRecommendProduct")
    public APIObjResponse<Integer> addRecommendProduct(@Validated @RequestBody AddRecommendProductModel addRecommendProductModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.productRecommendBiz.addRecommendProduct(addRecommendProductModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 删除推荐商品
     * @return
     */
    @ApiOperation(value = "删除推荐商品", httpMethod = "POST")
    @PostMapping(value = "/delRecommendProduct")
    public APIObjResponse<Integer> delRecommendProduct(@Validated @RequestBody DelRecommendProductModel delRecommendProductModel){
        int result = this.productRecommendBiz.delRecommendProduct(delRecommendProductModel);
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 修改推荐商品排序值
     * @param updateRecommendProductSortModel
     * @return
     */
    @ApiOperation(value = "修改推荐商品排序值", httpMethod = "POST")
    @PostMapping(value = "/updateRecommendProductSort")
    public APIObjResponse<Integer> updateRecommendProductSort(@Validated @RequestBody UpdateRecommendProductSortModel updateRecommendProductSortModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.productRecommendBiz.updateRecommendProductSort(updateRecommendProductSortModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

}
